<?php

namespace App\Http\Controllers\Admin;

use App\Http\Model\Logs;
use App\Http\Model\Notice;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Session;

class NoticeController extends Controller
{
    /**
     * 公告管理
     * @return $this
     */
    public function notice(){
        check_auth();
        $notices=Notice::orderBy('id','asc')->get()->all();
        return view('admin.notice.notice',compact('notices'))->with(['title'=>'公告管理']);
    }

    /**
     * 添加公告
     * @return array
     */
    public function addNotice(){
        if($input=Input::except('_token')){
            return (bool)Notice::create($input)?['status'=>1,'msg'=>'添加成功']:['status'=>0,'msg'=>'添加失败'];
        }
    }

    /**修改状态
     * @return array
     */
    public function updateNoticeStatus(){
        check_auth();
        if($input=Input::all()){
            $status=$input['status'];
            if(Notice::where('id',$input['id'])->update(['status'=>$status])){
                return ['status'=>1,'msg'=>'修改完成'];
            }else{
                return ['status'=>0,'msg'=>'修改失败'];
            }
        }
    }

    /**删除宫公告
     * @return array
     */
    public function deleteNotice(){
        check_auth();
        if($input=Input::all()){
            if(Notice::where('id',$input['id'])->delete()){
                return ['status'=>1,'msg'=>'修改完成'];
            }else{
                return ['status'=>0,'msg'=>'修改失败'];
            }
        }
    }
}
